import request from "umi-request";
import {message} from "antd"

request.interceptors.request.use((url, options) => {
  return {
    url: `${url}`,
    options: { ...options, interceptors: true },
  };
});

// handling error in response interceptor
request.interceptors.response.use(response => {
  if (response.status > 400) {
    const codeMaps = {
      404: '找不到',
      502: '网关错误。',
      503: '服务不可用，服务器暂时过载或维护。',
      504: '网关超时。',
    };
    // @ts-ignore
    message.error(codeMaps[response.status]);
  }
  return response;
});

export default request
